<?php
class ControllerSoftDoctorreport extends Controller
{
	function index()
	{	
		$dt = getdate();
		$year = $dt['year'];
		$this->data['curentyear'] = $dt['year'];
		$this->data['curentmonth'] = $dt['mon'];
		for($i= $year - 10;$i<$year +10;$i++)
			$this->data["Year"][] =$i;
		for($i=1;$i<=12;$i++)
			$this->data["Month"][] =$i;
		$this->id='content';
		$this->template='soft/doctorreport.tpl';
		$this->layout='layout/center';
		$this->render();
	}
	
	public function getList()
	{
		$startdate=$this->date->formatViewDate($this->request->get['startdate']);
		$enddate=$this->date->formatViewDate($this->request->get['enddate']);
		$listorder = $this->getListOrder($startdate,$enddate,"sale");
		
		$this->getListDoctor();
		
		foreach($this->data['doctors'] as $key => $item)
		{
			//get list order by doctor
			//$where = " AND doctor = '".$item['doctor']."'";
			$list = $this->string->array_Filter($listorder,"doctor",$item['userid']);
			$sum = 0;
			foreach($list as $val)
			{
				$sum+=$val['total'];
			}
			$this->data['doctors'][$key]['sum'] = $sum;
		}
		
		$this->template='soft/doctorreportlist.tpl';
		$this->render();
	}
	
	public function getListDoctor()
	{
		$this->load->model("core/user");
		$where = " AND usertypeid = 'doctor' ";
		$this->data['doctors'] = $this->model_core_user->getList($where);
	}
	
	function getListOrder($startdate,$enddate,$type)
	{
		$this->load->model("addon/order");
		$wherestart = "";
		$whereend = "";
		if($this->request->get['startdate'] !="")
			$wherestart = "AND orderdate >= '".$startdate."' ";
		if($this->request->get['enddate'] !="")
			$whereend = "AND orderdate  <= '".$enddate."'";
		$where = " AND `type` = '".$type."' 
					".$wherestart."
					".$whereend."
					ORDER BY  `order`.`orderdate` DESC ";
		
		$list = $this->model_addon_order->getListOrder($where);
		return $list;
	}
}
?>